#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDesktopWidget>

bool isRunning;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    isRunning=false;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::on_pushButton_clicked()
{

    if(!isRunning){
        QString SPort = ui->lineEdit->text();
        int port=SPort.toInt();
        // create thread which periodicaly takes screenshots (constructors takes window id as argument)
        screencapture = new ScreenCapture(QApplication::desktop()->winId(),port);
        screencapture->start();

        ui->label_2->setText("Server is running.");
        ui->pushButton->setText("Stop Server");
        isRunning=true;
    }else{
        delete screencapture;
        ui->label_2->setText("Server is not running.");
        ui->pushButton->setText("Start Server");
        isRunning = false;

    }

}
